package org.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.exception.AppException;
import org.example.exception.AppExceptionCodeMsg;
import org.example.pojo.Disease;
import org.example.query.DiseaseQuery;
import org.example.service.IDiseaseService;
import org.example.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author peak
 * @since 2024-12-18
 */
@RestController
@RequestMapping("/disease")
public class DiseaseController  {

    @Autowired
    private IDiseaseService diseaseService;
    @RequestMapping("/conditions")
    public ResultBean conditions(@RequestBody Disease disease) {
        if(disease.getDiseaseCode()==null || "".equals(disease.getDiseaseName())) {
            throw new AppException(AppExceptionCodeMsg.PARAMS_EMPTY);
        }
        //人们在搜索的时候不一定按照这个编码进行搜索
        //不等于空的时候才让它加入这个查询中
        QueryWrapper<Disease> queryWrapper=new QueryWrapper<>();
        //这里由于是一个字符串，肯定不能精准查询啊
        queryWrapper.like("disease_code",disease.getDiseaseCode());
        queryWrapper.like("disease_name",disease.getDiseaseName());
        List<Disease> diseases = diseaseService.list(queryWrapper);
        return ResultBean.SUCCESS(diseases);
    }
}
